import {nativeImage, Menu, ipcMain, shell, BrowserWindow, webContents} from 'electron';

function about() {
    const window = BrowserWindow.fromWebContents(webContents.getFocusedWebContents());
    const win = new BrowserWindow({
        devTools: false,
        maximizable: false,
        minimizable: false,
        title: '关于我们',
        parent: window,
        height: 300,
        useContentSize: false,
        width: 600,
        frame: true,
        modal: true,
    });
    win.setMenu(null);
}

ipcMain.on('setting', (event, data) => {
    let start = nativeImage.createEmpty();
    start.addRepresentation({dataURL: ''});

    let end = nativeImage.createEmpty()
    end.addRepresentation({dataURL: ''});

    let setting = nativeImage.createEmpty()
    setting.addRepresentation({dataURL: ''});

    let qun = nativeImage.createEmpty()
    qun.addRepresentation({dataURL: ''});

    let gitHub = nativeImage.createEmpty()
    gitHub.addRepresentation({dataURL: ''});

    const rightM = Menu.buildFromTemplate([
        {label: '开始全部任务', enabled: false, icon: start},
        {label: '暂停全部任务', enabled: false, icon: end},
        {label: '本次传输完自动关机'},
        {type: 'separator'},
        {label: '设置', icon: setting,},
        {
            label: '关于', click: () => {
                about()
            }
        },
        {
            label: '版本升级',
            click: () => {
                event.sender.send('appUpdate','appUpdate');
            }
        },
        {label: '问题反馈'},
        {type: 'separator'},
        {
            label: '加入qq群',
            icon: qun,
            click: () => {
                shell.openExternal('tencent://groupwpa/?subcmd=all&param=7B2267726F757055696E223A3831343237303636392C2274696D655374616D70223A313533393531303138387D0A');
            }
        },
        {
            label: 'GitHub地址', icon: gitHub,
            click: () => {
                shell.openExternal('https://github.com/lihaotian0607/auth');
            }
        },
    ]);
    // Menu.setApplicationMenu(rightM);
    rightM.popup({});
});